package com.jumi.microservice.controller.api;

/**
 * @author Scw
 * @Date 2020-08-19 15:21
 */

import com.jumi.microservice.common.base.BaseController;
import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.common.page.TableDataInfo;
import com.jumi.microservice.constant.refundgoods.CancelUserFlagEnum;
import com.jumi.microservice.dto.admin.refund.AdminRefundRequest;
import com.jumi.microservice.dto.refundgoods.*;
import com.jumi.microservice.service.admin.AdminRefundService;
import com.jumi.microservice.service.api.RefundGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author Scw
 * @Date 2020-08-19 10:10
 */
@Api(tags = {"C端--售后管理--相关接口"})
@RestController
@RequestMapping("/api/refundGoods")
public class RefundGoodsController extends BaseController {
    @Resource
    private RefundGoodsService refundGoodsService;
    @Resource
    private AdminRefundService adminRefundService;

    @ApiOperation("商品出库中弹窗提示")
    @PostMapping("/refundDelivery")
    public ResponseResult<String> refundDelivery(@ApiParam(name = "orderId", value = "订单Id", example = "1") @RequestParam("orderId") Integer orderId, @ApiParam(name = "skuIdStr", value = "商品Id,多个英文逗号分隔", example = "1,2") @RequestParam("skuIdStr") String skuIdStr) {
        ResponseResult<String> result = new ResponseResult<>();
        result.setData(refundGoodsService.refundDelivery(orderId, skuIdStr));
        return result;
    }

    @ApiOperation("退款添加")
    @PostMapping("/addRefund")
    public ResponseResult<Boolean> addRefund(AdminRefundRequest adminRefundRequest) {
        adminRefundRequest.setOperatorId(getApiUserId().longValue());
        adminRefundRequest.setOperatorName(getApiUserName());
        adminRefundRequest.setUserFlag(CancelUserFlagEnum.USER_FLAG_CUSTOMER.getCode().byteValue());
        return adminRefundService.addRefund(adminRefundRequest);
    }

    @PostMapping(value = "/addRefundGoods")
    @ApiOperation("退货添加")
    public ResponseResult<Boolean> addRefundGoods(RefundGoodsAddRequest refundGoodsAddRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        refundGoodsAddRequest.setOperatorId(getApiUserId().longValue());
        refundGoodsAddRequest.setOperatorName(getApiUserName());
        result.setData(refundGoodsService.addRefundGoods(refundGoodsAddRequest));
        return result;
    }

    @PostMapping(value = "/addRefundGoodsLogistics")
    @ApiOperation("物流信息添加")
    public ResponseResult<Boolean> addRefundGoodsLogistics(RefundGoodsLogisticsRequest refundGoodsLogisticsRequest, RefundGoodsRequest refundGoodsRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        refundGoodsLogisticsRequest.setOperatorId(getApiUserId().longValue());
        refundGoodsLogisticsRequest.setOperatorName(getApiUserName());
        refundGoodsRequest.setUid(getApiUserId().longValue());
        result.setData(refundGoodsService.addRefundGoodsLogistics(refundGoodsLogisticsRequest, refundGoodsRequest));
        return result;
    }

    @PostMapping(value = "/delRefundGoods")
    @ApiOperation("售后服务-删除记录")
    public ResponseResult<Boolean> delRefundGoods(RefundGoodsDelRequest refundGoodsDelRequest, RefundGoodsRequest refundGoodsRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        refundGoodsDelRequest.setOperatorId(getApiUserId().longValue());
        refundGoodsDelRequest.setOperatorName(getApiUserName());
        refundGoodsRequest.setUid(getApiUserId().longValue());
        result.setData(refundGoodsService.delRefundGoods(refundGoodsDelRequest, refundGoodsRequest));
        return result;
    }

    @PostMapping(value = "/cancelRefundGoods")
    @ApiOperation("退货取消")
    public ResponseResult<Boolean> cancelRefundGoods(RefundGoodsStatusRequest refundGoodsStatusRequest, RefundGoodsRequest refundGoodsRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        refundGoodsStatusRequest.setOperatorId(getApiUserId().longValue());
        refundGoodsStatusRequest.setOperatorName(getApiUserName());
        refundGoodsRequest.setUid(getApiUserId().longValue());
        result.setData(refundGoodsService.cancelRefundGoods(refundGoodsStatusRequest, refundGoodsRequest));
        return result;
    }

    @PostMapping(value = "/refundGoodsDetail")
    @ApiOperation("售后详情")
    public ResponseResult<RefundGoodsInfoResponse> refundGoodsDetail(RefundGoodsRequest refundGoodsRequest) {
        //获取当前用户ID
        refundGoodsRequest.setUid(getApiUserId().longValue());
        ResponseResult<RefundGoodsInfoResponse> result = new ResponseResult<>();
        result.setData(refundGoodsService.refundGoodsDetail(refundGoodsRequest));
        return result;
    }

//    @GetMapping("/refundGoodsStatus/dictionary")
//    @ApiOperation("退货状态对照字典")
//    public ResponseResult<List<AppTypeListResponse>> getRefundGoodsStatus() {
//        ResponseResult<List<AppTypeListResponse>> result = new ResponseResult<>();
//        result.setData(refundGoodsService.getRefundGoodsStatus());
//        return result;
//    }
//
//    @GetMapping("/afterSaleReason/dictionary")
//    @ApiOperation("售后原因对照字典")
//    public ResponseResult<List<AppTypeListResponse>> getAfterSaleReason() {
//        ResponseResult<List<AppTypeListResponse>> result = new ResponseResult<>();
//        result.setData(refundGoodsService.getAfterSaleReason());
//        return result;
//    }

    @GetMapping("/refundReason/dictionary")
    @ApiOperation("退货原因对照字典")
    public ResponseResult<List<AppTypeListResponse>> getRefundReason() {
        ResponseResult<List<AppTypeListResponse>> result = new ResponseResult<>();
        result.setData(refundGoodsService.getRefundReason());
        return result;
    }

    @GetMapping("/refundMoneyReason/dictionary")
    @ApiOperation("退款原因对照字典")
    public ResponseResult<List<AppTypeListResponse>> getRefundMoneyReason() {
        ResponseResult<List<AppTypeListResponse>> result = new ResponseResult<>();
        result.setData(refundGoodsService.getRefundMoneyReason());
        return result;
    }

    @GetMapping("/refundList")
    @ApiOperation("售后服务--全部列表")
    TableDataInfo<RefundListResponse> refundList(RefundListRequest request) {
        //获取当前用户ID
        request.setUid(getApiUserId().longValue());
        return refundGoodsService.refundList(request);
    }

    @GetMapping("/refundWaitList")
    @ApiOperation("售后服务--待处理列表")
    TableDataInfo<RefundListResponse> refundWaitList(RefundListRequest request) {
        //获取当前用户ID
        request.setUid(getApiUserId().longValue());
        return refundGoodsService.refundWaitList(request);
    }

    @GetMapping("/refundOrderList")
    @ApiOperation("售后列表【订单】")
    ResponseResult<List<RefundListByOrderResponse>> refundOrderList(RefundListByOrderRequest request) {
        //获取当前用户ID
        request.setUid(getApiUserId().longValue());
        ResponseResult<List<RefundListByOrderResponse>> result = new ResponseResult<>();
        result.setData(refundGoodsService.refundOrderList(request));
        return result;
    }
}